<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目合格证信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<!-- 删除按钮权限 -->
<sys:funcAuth resCd="delPrjPrdVeh">
	<span id="isShowDelBtn" />
</sys:funcAuth>

<script type="text/javascript">
	var grid = null;
	$(function () {
		initGrid();
        $("#searchBar").ligerForm();
        $("#searchBtn").click(function(event) {
             var form = new liger.get("searchBar");
             var data = form.getData();
             for (name in data){
                grid.setParm(name,data[name]);
             };
            grid.reload();
        });
	});
	function clearBtn(){
        $("#searchBar").ligerForm();
        var form = new liger.get("searchBar");
        form.setData({
            lsCntNo:" ",
            cstNm:" ",
            prjTypCd:" ",
            isHaveVeh:" ",
            isUploadFile:" ",
            paySchNo:" ",
            certNo:" ",
            buOrgCd:" ",
            gpsAudStsCd:" "
        });
	}
	//初始化列表
	function initGrid(){
		var params = {};
		$("#grid").ligerGrid({
	    	url: '<%=path%>/project/prjprdvehinfo/initList.do',
	    	method : 'get',
	    	parms:params,
	        columns: [
	            { display: '合格证号', name: 'certNo', minWidth: 80 ,align:'left',
	  	            	render: function (rowdata, rowindex, value, column) {
	  	            		var no = rowdata.certNo==null?" ":rowdata.certNo;
	  	            		var h = '';
	  	            		if(no&&rowdata.isDel==CommonConstant.C_YN_N_0){
	  	            		    h='<a  href="javascript:detailBtn(';
	  	                        h+="'"+rowdata.id+"',";
	  	                        h+="'"+rowdata.dtlId+"'";
	  	                        h+=')">'+no+'</a>'
	  	            		}
	  	                    return h;
	  	            		},
	  	            	enabledSort:true},
	            { display: '合同号', name: 'lsCntNo', minWidth: 80 ,align:'left',enabledSort:true},
	            { display: '客户名称', name: 'cstNm', minWidth: 60,align:'left',enabledSort:true},
	            { display: '项目类型', name: 'prjTypCdNm', minWidth: 60,align:'left',enabledSort:true}, 
	            { display: '业务类型', name: 'bizTypCdNm', minWidth: 60,align:'left', enabledSort:true}, 
                { display: '租赁物名称', name: 'prdNm', minWidth: 80,align:'left',enabledSort:true},
                { display: '支付表号', name: 'paySchNo', minWidth: 100,align:'left',enabledSort:true},
                { display: '车架号', name: 'vin', minWidth: 80,align:'left',enabledSort:true},
	        	{ display: '合格证审核状态', name: 'audStsCdNm', minWidth: 100,align:'left',enabledSort:true},
	        	{ display: 'GPS审核状态', name: 'gpsAudStsNm', minWidth: 70,align:'left',enabledSort:true},
                {
	                display: '操作',
	                isSort: false,
	                width: 200,
	                align:'left',
	                render: function (rowdata, rowindex, value){
                          var h="";
                          if(rowdata.certNo&&rowdata.isDel==CommonConstant.C_YN_N_0){

                              /**
                               * 【修改】按钮显示条件
                               * 合格证审核状态（audStsCd，PRJ0112）：0-未审核， 1-审核中，2-审核通过
                               * GPS审核状态（gpsAudStsCd，SYS0055）：0-未审核，1-审核中，2-审核通过，3-审核不通过，4-驳回呈报人
                               *
                               * 合格证和GPS只要有一个是未审核，就显示【修改】按钮
                               *
                               * 合格证与GPS都是未审核状态时，同时修改合格证与GPS信息；
                               * 合格证未审核，GPS非 未审核状态，仅修改合格证信息
                               * GPS未审核，合格证非 未审核状态，仅修改GPS
                               *
                               */
                              if ((rowdata.audStsCd == 4) || (rowdata.gpsAudStsCd == 4) ||(rowdata.audStsCd == 0) || (rowdata.gpsAudStsCd == 0) || (typeof rowdata.gpsAudStsCd == "undefined"  || rowdata.gpsAudStsCd == null || rowdata.gpsAudStsCd == "")) {
                                  h = '<a class="sq-button-hasicon" href="javascript:modifyBtn(';
                                  h += "'" + rowdata.id + "',";
                                  h += "'" + rowdata.dtlId + "',";
                                  h += "'" + rowdata.audStsCd + "'";
                                  h += ')"><i class="sqBtnIco_4"></i>修改</a>';

                                  var isShowDelBtn = $("#isShowDelBtn");
                                  if (isShowDelBtn.length) {
                                      h += '<a class="sq-button-hasicon" href="javascript:removeBtn(';
                                      h += "'" + rowdata.id + "'";
                                      h += ')"><i class="sqBtnIco_7"></i>删除</a>';
                                  }
                              }
                          }

                          // 验证是否可以 "变更GPS"
                          if (rowdata.gpsAudStsCd == 2 ||rowdata.gpsAudStsCd == 3){// GPS审核状态：0.未审核 1.审核中 2.已审核 3.审核不通过
                                h+='<a class="sq-button-hasicon" href="javascript:changeGPS(';
                                h+="'"+rowdata.id+"',";
                                h+="'"+rowdata.dtlId+"'";
                                h+=')"><i class="sqBtnIco_7"></i>变更GPS</a>';
                          }
                          // 显示GPS变更流程
                          if (StringUtils.isNotEmpty(rowdata.gpsPNo)){
                                h+='<a class="sq-button-hasicon" href="javascript:commShowFlowForGPS(';
                                h+="'"+rowdata.gpsPInsId+"',";
                                h+="'"+rowdata.gpsPSts+"',";
                                h+="'"+rowdata.gpsPBusId+"'";
                                h+=')"><i class="sqBtnIco_4"></i>'+rowdata.gpsPNo+'</a>';
                          }
	                      return h;
	                }
	            }  
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        allowUnSelectRow: true,
            alternatingRow: true,
	        rownumbers:true,
	        enabledEdit: true,
            isSingleCheck:true,
            onSelectRow:function(rowdata, rowid, rowobj){
                if(rowdata.audStsCd == '2'){
                    $("#addBtn").hide();
                } else {
                    $("#addBtn").show();
                }
            },
            onUnSelectRow:function(rowdata, rowid, rowobj){
                $("#addBtn").show();
            }
	    });
		grid = liger.get("grid");
		grid.setHeight(500);
		
	}

    function commShowFlowForGPS(_pInstId,_audStsCd,_businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/project/prjprdvehinfo/toAddPage.do?isEdit=0@@applyId=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_gps_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }

	//添加合格证信息
	function addBtn(){
		var callback = function(){
			 grid.reload();
		}
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length !=1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		var dtlId = selectedRows[0].dtlId;
		var detailFlag = false;
		var timestamp=new Date().getTime();
        var noLinkButton = true;
		Add_navTab( 'tab_prj_prd_veh_info_add'+timestamp,'添加合格证','<%=path%>/project/prjprdvehinfo/toAddPage.do?detailFlag='+detailFlag+'&&dtlId='+dtlId + '&noLinkButton=' + noLinkButton,callback);
	}
	
	//修改合格证信息
	function modifyBtn(id,dtlId,audStsCd){
		var callback = function(){
			 grid.reload();
		}
		var detailFlag = false;
		var noLinkButton = true;
        Add_navTab( 'tab_prj_prd_veh_info_modify'+id,'修改合格证','<%=path%>/project/prjprdvehinfo/toAddPage.do?detailFlag='+detailFlag+'&&id='+id+'&&dtlId='+dtlId + '&noLinkButton=' + noLinkButton,callback);
	}
	// 变更GPS
    function changeGPS(id,dtlId) {
        var callback = function(){
            grid.reload();
        }
        var detailFlag = false;
        Add_navTab( 'tab_prj_prd_veh_info_modifyGPS'+id,'变更GPS','<%=path%>/project/prjprdvehinfo/toAddPage.do?detailFlag='+detailFlag+'&&id='+id+'&&handleType=1'+'&&dtlId='+dtlId,callback);
    }

	function detailBtn(id,dtlId){
		var detailFlag = true;
		Add_navTab( 'tab_prj_prd_veh_info_detail'+id,'合格证详情','<%=path%>/project/prjprdvehinfo/toDetailPage.do?detailFlag='+detailFlag+'&&id='+id+'&&dtlId='+dtlId);
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//删除所选合格证信息
	function removeBtn(id){
		var _ids = [];
		_ids.push(id);
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/project/prjprdvehinfo/removeByIds.do',
				success:function(msg){
					 if(msg.success == 1){
						 grid.reload();
					 }else{
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					 }
				}
			});
		});
		
	}
</script>

    <body class="iframeBody">
        <div class="Wrapper">
            <div id="pageInTab" class="pageInTab">
                <div class="searchArea">
                    <form id="searchBar">
                        <div class="fieldset1 clearFix">
                             <div class="fieldBox col_33">
                                    <div class="label">客户名称</div>
                                    <div class="field">
                                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                                    </div>
                             </div>
                             <div class="fieldBox col_33">
                                <div class="label">合同号</div>
                                <div class="field">
                                    <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                                </div>
                             </div>
                             <div class="fieldBox col_33">
                                <div class="label">支付表号</div>
                                <div class="field">
                                    <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                                </div>
                             </div>
                             <div class="fieldBox col_33">
                                <div class="label">合格证编号</div>
                                <div class="field">
                                    <input name="certNo" id="certNo" type="text" class="ui-textbox" value="">
                                </div>
                             </div>
                             <div class="fieldBox col_33" id="searchPrjTypCdId">
                                  <div class="label">项目类型</div>
                                  <div class="field">
                                      <select name="prjTypCd"  id="prjTypCd" >
                                         <option value="  " selected="selected">--请选择--</option>
                                         <c:forEach items="${projectTypeList}" var="opt">
                                            <option value="${opt.key}">${opt.value}</option>
                                         </c:forEach>
                                      </select>
                                  </div>
                             </div>
                             <div class="fieldBox col_33" style="display: none">
                                   <div class="label">是否上传资料</div>
                                   <div class="field">
                                       <select name="isUploadFile"  id="isUploadFile"  >
                                           <option value="  " selected="selected">--请选择--</option>
                                           <c:forEach items="${isYesList}" var="opt">
                                            <option value="${opt.key}">${opt.value}</option>
                                           </c:forEach>
                                       </select>
                                   </div>
                             </div>
                             <div class="fieldBox col_33">
                                    <div class="label">是否录入合格证</div>
                                    <div class="field">
                                        <select name="isHaveVeh"  id="isHaveVeh"  >
                                             <option value="  " selected="selected">--请选择--</option>
                                             <c:forEach items="${isYesList}" var="opt">
                                              <option value="${opt.key}">${opt.value}</option>
                                             </c:forEach>
                                        </select>
                                    </div>
                             </div>
                             <div class="fieldBox col_33">
                                   <div class="label">所属事业部</div>
                                   <div class="field">
                                       <select name="buOrgCd" id="buOrgCd">
                                           <option value=" " seleted>请选择</option>
                                           <c:forEach items="${buOrgCdList }" var="org">
                                               <c:if test="${currentBuOrgCd == org.key }">
                                                   <option value="${org.key }" selected>${org.value }</option>
                                               </c:if>
                                               <c:if test="${currentBuOrgCd != org.key }">
                                                   <option value="${org.key }">${org.value }</option>
                                               </c:if>
                                           </c:forEach>
                                       </select>
                                   </div>
                             </div>
                             <div class="fieldBox col_33">
                                   <div class="label">GPS审核状态</div>
                                   <div class="field">
                                       <select name="gpsAudStsCd" id="gpsAudStsCd">
                                           <option value="  " selected="selected">--请选择--</option>
                                           <c:forEach items="${gpsAudStsList }" var="org">
                                               <option value="${org.key }">${org.value }</option>
                                           </c:forEach>
                                       </select>
                                   </div>
                             </div>
                             <div class="fieldBox col_33">
                                   <div class="label">合格证审核状态</div>
                                   <div class="field">
                                       <select name="certNoAudStsCd" id="certNoAudStsCd">
                                           <option value="  " selected="selected">--请选择--</option>
                                           <c:forEach items="${certNoAudStsCd}" var="certNoAudStsCd">
                                               <option value="${certNoAudStsCd.key}">${certNoAudStsCd.value}</option>
                                           </c:forEach>
                                       </select>
                                   </div>
                             </div>
                             <div class="clearFix"></div>
                             <div class="btnsBox">
                                   <span id="searchBtn"  class="sq-button sq-button-round">查询</span>
                                   <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
                                   <span id="addBtn" onclick="addBtn();" class="sq-button sq-button-round">新增</span>
                             </div>
                        </div>
                    </form>
                    <div id="grid" class="sq-grid"></div>
                </div>
            </div>
        </div>
    </body>
</html>